﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BKDict.Data_Access;

namespace BKDict.Logic
{
    public class DictionManager
    {
        public string MFile { get; set; }
        public string KFile { get; set; }

        public DictionManager(string _mfile, string _kfile)
        {
            MFile = _mfile;
            KFile = _kfile;
        }


        public int Base64ToBase10(string num)
        {
            int number = 0;
            int len = num.Length;
            string opcode = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
            for (int i = 0; i < len; i++)
            {
                number += opcode.IndexOf(num[i]) * (int)Math.Pow(64, len - i - 1);
            }
            return number;
        }

        public string getMean(long offset, int length)
        {
            return new DictionAccess(MFile, KFile).getMean(offset, length);
        }

        public List<string> getListKey()
        {
            List<string> result = new List<string>();
            string temp;
            string[] word = new string[5];

            IEnumerator<string> lstkey = new DictionAccess(MFile, KFile).getListKey();
            while (lstkey.MoveNext())
            {
                word = lstkey.Current.Trim().Split('\t');
                temp = (word[0] + "\t" + Base64ToBase10(word[1]) +"\t"+ Base64ToBase10(word[2]));
                result.Add(temp);
            }

            return result;
        }
    }
}
